package midalgorithms.sortandsearch;

import java.util.Arrays;

public class _07SearchRound {
    public static int search(int[] nums, int target) {
        if (nums.length == 1){
            return Arrays.binarySearch(nums,target) < 0 ? -1 : Arrays.binarySearch(nums,target);
        }
        int[] sortNum = new int[nums.length];
        int index = 0,k = 0;
        while (k < nums.length-1 && nums[k] < nums[k+1]){
            k++;
        }
        k++;
        int kk = k;
        while (index < sortNum.length){
            sortNum[index++] = nums[(kk) % nums.length];
            kk++;
        }
        return Arrays.binarySearch(sortNum,target) < 0 ? -1 : (k+Arrays.binarySearch(sortNum,target)) % nums.length;
    }
}
